
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:xlp_github_app_flutter/page/main/index.dart';
import 'package:xlp_github_app_flutter/redux/app_state.dart';
import 'package:xlp_github_app_flutter/utils/icons.dart';

import '../widget/index.dart';

class MainPage extends StatefulWidget {
  static const String sName = "main";

  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  final PageController pageController = PageController();
  int currentIndex = 0;

  void onIndexChanged(int index) {
    setState(() {
      currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return StoreBuilder<AppState>(builder: (context, store) {
      return Scaffold(
        extendBody: true, // 扩展到Scaffold的底部
        resizeToAvoidBottomInset: false, // 不允许键盘事件影响界面
        body: PageView(
          physics: const NeverScrollableScrollPhysics(),
          controller: pageController,
          onPageChanged: onIndexChanged,
          children: const [
            IndexPage(title: "index"),
            IndexPage(title: "map"),
            IndexPage(title: "work"),
            IndexPage(title: "mine"),
          ],
        ),

        bottomNavigationBar: BuildNavigation(currentIndex: currentIndex,
          items: [
            NavigationItemModel(
              label: "home",
              icon: SvgIcon.layout,
            ),
            NavigationItemModel(
              label: "map",
              icon: SvgIcon.marker,
            ),
            NavigationItemModel(
              label: "chat",
              icon: SvgIcon.chat,
              count: 3,
            ),
            NavigationItemModel(
              label: "user",
              icon: SvgIcon.user,
            ),
          ],
          onTap: onIndexChanged, // 切换tab事件
        ),
      );
    });
  }
}